package saeildamil.ch18.communication;

import javax.swing.JOptionPane;

public class PrintPIThread extends Thread {
	SharedArea sharedArea;

	public PrintPIThread(SharedArea sharedArea) {
		this.sharedArea = sharedArea;
	}
	
	@Override
	public void run() {
		if(sharedArea.isReady != true){		// PI의 값이 나오지 않았다면...
			synchronized (sharedArea) {
				try {
					JOptionPane.showMessageDialog(null, "대기 중입니다.");
					sharedArea.wait();		// PI에게서 notify()가 올 때까지 대기;
				} catch (InterruptedException e) {
					System.out.println(e.getMessage());
				}
			} 
		}// end of if;
		JOptionPane.showMessageDialog(null, "PI는 : " + sharedArea.result);
	}//end of run;
}// end of PrintPIThread;
